import { ApiCall } from "tsrpc";
import { ReqRegister, ResRegister } from "../../shared/master/PtlRegister";
import { player, wallet_key } from "../../model/fight/body/player";
import manage_user from "../model/manage/manage_user";
import { template } from "../../shared/master/MsgAction";
import manage_word from "../model/manage/manage_word";
import app, { xlsxCfgNames } from "../../app";
import { SKILL } from "../../model/fight/skill/SK_active";
import SK_func from "../../model/fight/skill/SK_func";
import { pet } from "../../model/fight/body/pet";
import { EffectType, group } from "../../shared/interface";
import god from "../../god";
import { prop_equip } from "../../model/bag/prop_equip";

export default async function (call: ApiCall<ReqRegister, ResRegister>) {
    call.succ({})

    let _onlyid = `${call.req._platform}_${call.req._onlyid}`;
    let haveRegister = await manage_user.has(_onlyid);
    if (haveRegister) {
        haveRegister.sendMsg(template.default, `重复注册`)
        return;
    }
    let user = new player();
    user.uuid = _onlyid;
    // 
    // user.leve.num = 99999;
    user.addSkill(new SKILL(SK_func.createSkill('普通攻击', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('盾反', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('黑暗契约', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('屏障', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('不灭之握', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('魔法攻击', 500)))
    // user.addSkill(new SKILL(SK_func.createSkill('物理吸血', 500)))
    // 宠物添加测试
    // const table = app.xlsxCfgMap.get(xlsxCfgNames.召唤表) as Map<string, any>;
    // let body = app.createUnity('1', 1, table, 100, 2) as pet;
    // body.name = '测试宠物';
    // user.addPet(body);

    // _player.addSkill(new SKILL(SK_func.getSkCfg_name('生命避难所')))
    // _player.addSkill(new SKILL(SK_func.getSkCfg_name('沉默打击')))

    // 测试道具
    if (app.getCfg(xlsxCfgNames.调试id).has(_onlyid)) {
        user.wallet_change(wallet_key.gold, 10000000000)
        let item = app.createCfgItem('prop-17', 0, '主神空间');
        item.cont_change(30769428280);
        user.getBag().add(item);
        item = app.createCfgItem('prop-2', 100, '注册赠送')
        item.cont_change(999999999)
        user.getBag().add(item);
        item = app.createCfgItem('prop-20', 100, '注册赠送')
        item.cont_change(999999999)
        
        user.getBag().add(item);
        item = app.createCfgItem('prop-23', 100, '注册赠送')
        item.cont_change(999999999)
        user.getBag().add(item);
        app.createCfgItem('equip', 100, '注册赠送')
        user.addSkill(new SKILL(SK_func.createSkill('财迷', 500)))
    }

    // item = app.createCfgItem('prop-19', 0, '主神空间');
    // item.cont_change(99);
    // user.getBag().add(item);
    // const pet_item = app.createCfgItem('pet', 0, body.name, body.createCfg);
    // user.getBag().add(pet_item);
    // item = app.createCfgItem('team-1', 0, '主神空间');
    // item.cont_change(600);
    // user.getBag().add(item);

    // item.cont_change(600);
    // user.getBag().add(item);


    // item = app.createCfgItem('att-5', 0, '主神空间');
    // item.cont_change(600);
    // user.getBag().add(item);

    // item = app.createCfgItem('att-9', 0, '主神空间');
    // item.cont_change(600);
    // user.getBag().add(item);
    // user.P.Hp_Max = 1000;
    // item = app.createCfgItem('prop-5', 0, '主神空间');
    // item.cont_change(9998);
    // user.getBag().add(item);

    // 复活币 保底赠送
    let item = app.createCfgItem('prop-1', 0, '主神空间');
    item.cont_change(300);
    user.getBag().add(item);
    app.createCfgItem('equip-1', 300, '注册赠送').use(user, 1);
    app.createCfgItem('equip-8', 300, '注册赠送').use(user, 1);
    app.createCfgItem('equip-13', 300, '注册赠送').use(user, 1);
    user.title_value = god.getRandomTitleValue();
    // item = app.createCfgItem('prop-3', 0, '主神空间');
    // user.getBag().add(item);
    // user.getBag().add(app.createCfgItem('exp-2', 0, '主神空间'));
    // item = app.createCfgItem('prop-4', 0, '主神空间')
    // item.cont_change(9998);
    // user.getBag().add(item);
    // item = app.createCfgItem('skill-普通攻击', 100, '主神空间');
    // user.getBag().add(item);

    // item = app.createCfgItem('skill-不灭之握', 100, '主神空间');
    // user.getBag().add(item);
    // item = app.createCfgItem('prop-7', 100, '主神空间');
    // user.getBag().add(item);
    user.reset_job()
    user.reset_talent()
    user.init();
    user.style_id = god.getRamdomStyle()
    user.setConn(call.conn)
    user.setLastLocation(call.req._fromid as string)
    user.res_life({
        use_uuid: "0",
        use_name: "主神空间",
        sk_name: "救赎",
        group: group.客场,
        type: EffectType.none,
        val: -1
    })
    manage_user.addUser(user);
    user.sendMsg(template.RegisterSuccress);
}